#include <Inventor/Win/SoWin.h>
#include <Inventor/Win/viewers/SoWinExaminerViewer.h>
#include <Inventor/nodes/SoSphere.h>
#include <Inventor/nodes/SoTransform.h>
#include <Inventor/nodes/SoDirectionalLight.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/nodes/SoSeparator.h>

#include <tchar.h>


int _tmain(int argc, _TCHAR* argv[])
{
  HWND myWindow = SoWin::init(argv[0]);
  if (myWindow == nullptr) exit(1);

  // Construct all parts
  SoGroup *waterMolecule = new SoGroup;      // water molecule

  SoGroup *oxygen = new SoGroup;             // oxygen atom
  SoMaterial *redPlastic = new SoMaterial;
  SoSphere *sphere1 = new SoSphere;

  SoGroup *hydrogen1 = new SoGroup;          // hydrogen atoms
  SoGroup *hydrogen2 = new SoGroup;
  SoTransform *hydrogenXform1 = new SoTransform;
  SoTransform *hydrogenXform2 = new SoTransform;
  SoMaterial *whitePlastic = new SoMaterial;
  SoSphere *sphere2 = new SoSphere;
  SoSphere *sphere3 = new SoSphere;

  // Set all field values for the oxygen atom
  redPlastic->ambientColor.setValue(1.0, 0.0, 0.0);  
  redPlastic->diffuseColor.setValue(1.0, 0.0, 0.0); 
  redPlastic->specularColor.setValue(0.5, 0.5, 0.5);
  redPlastic->shininess = 0.5;
   
  // Set all field values for the hydrogen atoms
  hydrogenXform1->scaleFactor.setValue(0.75, 0.75, 0.75);  
  hydrogenXform1->translation.setValue(0.0, -1.2, 0.0);  
  hydrogenXform2->translation.setValue(1.1852, 1.3877, 0.0);
  whitePlastic->ambientColor.setValue(1.0, 1.0, 1.0);  
  whitePlastic->diffuseColor.setValue(1.0, 1.0, 1.0); 
  whitePlastic->specularColor.setValue(0.5, 0.5, 0.5);
  whitePlastic->shininess = 0.5;

  // Create a hierarchy
  waterMolecule->addChild(oxygen);   
  waterMolecule->addChild(hydrogen1);   
  waterMolecule->addChild(hydrogen2);

  oxygen->addChild(redPlastic);
  oxygen->addChild(sphere1);
  hydrogen1->addChild(hydrogenXform1);
  hydrogen1->addChild(whitePlastic);
  hydrogen1->addChild(sphere2);
  hydrogen2->addChild(hydrogenXform2);
  hydrogen2->addChild(sphere3);

  // Set up viewer:
  SoWinExaminerViewer *myViewer = 
          new SoWinExaminerViewer(myWindow);
  myViewer->setSceneGraph(waterMolecule);
  myViewer->setTitle("Water molecule");
  myViewer->show();

  SoWin::show(myWindow);
  SoWin::mainLoop();
}